package excel

import (
	"container/list"
	"path"
	"strings"

	"github.com/astaxie/beego/logs"
)

func ReadPhoneExcel(filepath string) (phoneList list.List, err error) {
	phoneMapList, err := ExcelCSVParser(filepath, _getFileSuffix(filepath), []string{"phone"})
	if err != nil {
		logs.Error("error ReadPhoneExcel %v", err.Error())
		return phoneList, err
	}
	for _, phoneMap := range phoneMapList {
		for _, v := range phoneMap {
			phoneList.PushBack(v)
		}
	}
	return phoneList, nil
}

func _getFileSuffix(filepath string) (fileSuffix string) {
	logs.Debug("_getFileSuffix filepath :", filepath)
	filenameWithSuffix := path.Base(filepath) //获取文件名带后缀
	fileSuffix = path.Ext(filenameWithSuffix) //获取文件后缀
	fileSuffix = strings.ToLower(fileSuffix)
	logs.Debug("_getFileSuffix filepath %v : suffer %v", filepath, fileSuffix)
	return
}
